<template>
  <div class='tab-control'>
    <div class="tab-control-item" v-for="(item, index) in titles" :key="index" :class="{tbactive: currentIndex == index}" @click="itemClick(index)">
      <span>{{item}}</span> 
    </div>
  </div>
</template>

<script>

export default {
  name: "tab-control",
  props: {
    titles: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index;
    }
  }
}
</script>

<style scoped>
  .tab-control {
    display: flex;
    background-color: white;
    text-align: center;
    line-height: 44px;
    position: sticky;
    top: 0px;
    z-index: 9;
  }

  .tab-control-item {
    flex: 1;
  }

  .tbactive span {
    color: var(--color-tint);
    padding: 3px 0;
    border-bottom: 2px solid var(--color-tint);
  }

</style>